let { player, foodList} = require('../gameData');
let EventServices = require('../../util/EventServices');
let { show } = require('../../game/alert');

cc.Class({
    extends: cc.Component,

    properties: {
       
    },
    onLoad () {
        this.addEvent();
        this.node.getChildByName('close').on(cc.Node.EventType.TOUCH_END, () => {
            this.node.destroy();
            this.node.parent.active = false;
            cc.find('Canvas/show/showShop').active = true;
        })
    },
    addEvent() {
        let arr = this.node.getChildByName('panel').children;
        arr = arr.slice(0,3);
        arr.forEach((val, index) => {
            val.on(cc.Node.EventType.TOUCH_END, () => {
                if(index == 2) {
                    this.selectFix(50, index+1);
                }else {
                    this.selectFix((index+1) * 10, index+1);
                }
            })
        })
    },
    selectFix (count, level) {
        console.log(count*10000)
        if(player.money >= count*10000){
            player.money -= count*10000;
            shop.status = 1;
            shop.level = level;
            shop.menuList = JSON.parse(JSON.stringify(foodList[level - 1].list));
            EventServices.publish('fixShop');   
            this.node.destroy();
        }else {
            show('未来银行',"账户余额不足，请充值");
        }
    },
    start () {

    },

    // update (dt) {},
});
